package com.sltx.controller;


import com.sltx.controller.base.BaseController;
import com.sltx.util.ImageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Controller
@RequestMapping("/image")
public class ImageController extends BaseController {


    @Autowired
    ImageUtil imageUtil;

    @PostMapping(path = "/upload")
    @ResponseBody
    public Map<String,String> uploadFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {

        Map<String, String> fileUrl = imageUtil.getFileUrl(file, request);

        if (fileUrl.get("msg")!=null){
            return null;
        }
        return fileUrl;
    }


    @PostMapping(path = "/upload2")
    @ResponseBody
    public String  uploadImage(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {

        return imageUtil.getImageUrl(file, request);
    }


}
